# -*- encoding: utf-8 -*-
"""
@File    : lstm_use.py
@Author  : lilong
@Time    : 2023/1/6 3:19 下午
"""

"""
参考: 
https://blog.csdn.net/qq_38980688/article/details/88794100
https://blog.csdn.net/hellocsz/article/details/89041723
https://www.zhihu.com/question/64470274?sort=created
https://blog.csdn.net/weixin_26938645/article/details/114729354
"""

from keras.models import Model
from keras.layers import Input
from keras.layers import LSTM
from keras.models import Sequential
from numpy import array


# [batch_size, seq_len, dim] = [1, 3, 1]
data = array([0.1, 0.2, 0.3]).reshape((1, 3, 1))

# -------网络结构------
# 分别指定TIME_STEPS和INPUT_SIZE，这里的是步长为3,维度为1
inputs1 = Input(shape=(3, 1))


# lstm1 存放的就是全部时间步的 hidden state
# state_h 存放的是最后一个时间步的 hidden state
# state_c 存放的是最后一个时间步的 cell state
lstm1, state_h, state_c = LSTM(2, return_sequences=True, return_state=True)(inputs1)
lstm2 = LSTM(2, return_sequences=True, return_state=False)(lstm1)
model = Model(inputs=inputs1, outputs=[lstm2])

lstm1_rst = model.predict(data)
print()


def use_2():
    """
    (10 * (10+5) + 10) * 4 = 640
    """

    time_step = 13
    input_dim = 5
    unit = 10

    model = Sequential()
    model.add(LSTM(unit, input_shape=(time_step, input_dim)))
    model.summary()


# if __name__ == '__main__':
#     use_1()
